<?php

/**
 * alter input core , get and post function 
 * @author licichun
 * @since Version 1.0
 * @addtime 2013-11-18
 */
class MY_Input extends CI_Input {

    function __construct() {
        parent::__construct();
    }

    /**
     * Fetch an item from the GET array by adslashes function
     *
     * @access	public
     * @param	string
     * @param	bool
     * @param    bool
     * @return	string
     */
    function getStr($index = NULL, $xss_clean = FALSE, $special = TRUE) {
        $str = $this->get($index, $xss_clean);
        if ($str != "" && $special === TRUE) {
            $str = addslashes(htmlspecialchars($str));
        }
        return $str;
    }

    /**
     * Fetch an item from the GET array by intval function
     *
     * @access	public
     * @param	string
     * @param	bool
     * @param   bool
     * @return	int
     */
    function getInt($index = NULL, $xss_clean = FALSE, $int = TRUE) {
        if ($int === TRUE) {
            return intval($this->get($index, $xss_clean));
        }
        return $this->get($index, $xss_clean);
    }
    
    function getFloat($index = NULL, $xss_clean = FALSE, $int = TRUE) {
        if ($int === TRUE) {
            return floatval($this->get($index, $xss_clean));
        }
        return $this->get($index, $xss_clean);
    }

    /**
     * Fetch an item from the POST array by adslashes function
     *
     * @access	public
     * @param	string
     * @param	bool
     * @param   bool
     * @return	string
     */
    function postStr($index = NULL, $xss_clean = FALSE, $special = TRUE) {
        $str = $this->post($index, $xss_clean);
        if ($str != "" && $special === TRUE) {
            $str = addslashes(htmlspecialchars($str));
        }
        return $str;
    }

    /**
     * Fetch an item from the POST array by intval function
     *
     * @access	public
     * @param	string
     * @param	bool
     * @param   bool
     * @return	int
     */
    function postInt($index = NULL, $xss_clean = FALSE, $int = TRUE) {
        if ($int === TRUE) {
            return intval($this->post($index, $xss_clean));
        }
        return $this->post($index, $xss_clean);
    }

    /*
     * get post传输
     */

    function getPostStr($index = NULL, $xss_clean = FALSE, $special = TRUE) {
        $str = $this->get_post($index, $xss_clean);
        if ($str != "" && $special === TRUE) {
            $str = addslashes(htmlspecialchars($str));
        }
        return $str;
    }
    
    function getPostFloat($index = NULL, $xss_clean = FALSE, $int = TRUE) {
        if ($int === TRUE) {
            return floatval($this->get_post($index, $xss_clean));
        }
        return $this->get_post($index, $xss_clean);
    }

    function getPostInt($index = NULL, $xss_clean = FALSE, $int = TRUE) {
        if ($int === TRUE) {
            return intval($this->get_post($index, $xss_clean));
        }
        return $this->get_post($index, $xss_clean);
    }

    function postFloat($index = NULL, $xss_clean = FALSE, $int = TRUE) {
        if ($int === TRUE) {
            return floatval($this->post($index, $xss_clean));
        }
        return $this->post($index, $xss_clean);
    }

    /*
     * 得到编辑器的内容
     */

    function postHtmlStr($index = NULL, $xss_clean = FALSE, $special = TRUE) {
        $str = $this->post($index, $xss_clean);
        if ($str != "" && $special === TRUE) {
            $str = preg_replace('/<script.*/i', '', $str);
            $str = preg_replace('/&lt;script.*/i', '', $str);
            $str = preg_replace('/<[\\?%].*/i', '', $str);
            $str = preg_replace('/&lt;[\\?%].*/i', '', $str);
        }
        return $str;
    }

}
